<?php
/*
	本插件：$this->model('model')->方法名();
	其他地方调用：model('jy_yxw/model')->方法名();
*/
namespace jy_yxw;
defined('BY_JYA') or exit('error');
class model extends \plugin{
	public function get_csvitems($rows){
			$num = count($rows);
			$i = 0;
			$colsIndex = $rows[1];
			$rows = array_slice($rows, 1, count($rows) - 1);
			$items = array();
			$num = 0;
			foreach ($rows as $rownu => $rv) {
				$item = array();
				foreach ($colsIndex as $cols => $cv) {
						$item[$cv]=$rv[$cols];
				}
				$items[] = $item;
				++$num;
			}
			return $items;
	}
	public function get_memberstatus($type=''){
		if($type=='shangmen'){
			$status=array(4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,32,33,34,35,36,37,38,39,40,41,42,100);
		}
		if($type=='ting'){
			$status=array(6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,32,33,34,35,36,37,38,39,40,41,42);
		}
		if($type=='xue'){
			$status=array(8,9,10,11,12,13,14,15,16,17,18,19,20,32,33,34,35,36,37,38,39,40,41,42,100);
		}
		if($type=='bao'){
			$status=array(4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,32,33,34,35,36,37,38,39,40,41,42,100);
		}
		return $status;
	}
	public function setstore($memberid=0,$storeid=0){
		pdo_update('jy_yxw_fenfee_log',array('storeid'=>$storeid),array('uniacid'=>$_SESSION['uniacid'],'memberid'=>$memberid));
		pdo_update('jy_yxw_genjin_log',array('storeid'=>$storeid),array('uniacid'=>$_SESSION['uniacid'],'memberid'=>$memberid));
		pdo_update('jy_yxw_infee_log',array('storeid'=>$storeid),array('uniacid'=>$_SESSION['uniacid'],'memberid'=>$memberid));
		pdo_update('jy_yxw_outfee_log',array('storeid'=>$storeid),array('uniacid'=>$_SESSION['uniacid'],'memberid'=>$memberid));
		pdo_update('jy_yxw_yonghu',array('fromstoreid'=>$storeid),array('uniacid'=>$_SESSION['uniacid'],'memberid'=>$memberid));
		pdo_update('jy_yxw_bufee_log',array('storeid'=>$storeid),array('uniacid'=>$_SESSION['uniacid'],'memberid'=>$memberid));
		return true;
	}
	public function checkjuese($juese=0){
		if($_SESSION['juese_id']==1 || $_SESSION['juese_id']==2 || $_SESSION['juese_id']==15){
			return true;
		}
		$jueses=pdo_getcolumn('jy_yxw_worker',array('uniacid'=>$_SESSION['uniacid'],'id'=>$_SESSION['workerid']),'jueses');
		if(strpos($jueses,';1;')!==false || strpos($jueses,';2;')!==false || strpos($jueses,';15;')!==false){
			return true;
		}
		if($_SESSION['juese_id']==$juese){
			return true;
		}
		if(strpos($jueses,';'.$juese.';')!==false){
			return true;
		}
		if($juese==3){
			if($_SESSION['juese_id']==3 || $_SESSION['juese_id']==4){
				return true;
			}
			if(strpos($jueses,';4;')!==false){
				return true;
			}
		}
		exi('您没有浏览权限！','error');
	}
	public function getworkerids($juese=0,$jia0=false){
		$workerids=pdo_getcolumn('jy_yxw_worker',array('uniacid'=>$_SESSION['uniacid'],'id'=>$_SESSION['workerid']),'workerids');
		$workerids=json_decode($workerids,true);
		if($jia0){
			$ids[0]=1;
		}
		$ids[$_SESSION['workerid']]=$_SESSION['workerid'];
		foreach($workerids as $wv){
			$ids[$wv['id']]=$wv['id'];
		}
		if($_SESSION['juese_id']==1 || $_SESSION['juese_id']==2 || $_SESSION['juese_id']==15 || $_SESSION['isjuese1'] || ($_SESSION['juese_id']==3 && $juese=5)){
			$workerids=pdo_getall('jy_yxw_worker',array('storeid'=>$_SESSION['storeids']?:$_SESSION['storeid'],'uniacid'=>$_SESSION['uniacid']),array('id'));
			foreach($workerids as $wv){
				$ids[$wv['id']]=$wv['id'];
			}
		}
		$ids=array_keys($ids);
		return $ids;
	}
	public function iszhuguan($juese=0){
		if($_SESSION['juese_id']==1 || $_SESSION['juese_id']==2 || $_SESSION['juese_id']==15){
			return true;
		}
		if($_SESSION['juese_id']==$juese){
			$num=1;
		}else{
			$jueses=pdo_getcolumn('jy_yxw_worker',array('uniacid'=>$_SESSION['uniacid'],'id'=>$_SESSION['workerid']),'jueses');
			if(strpos($jueses,';'.$juese.';')===false){
				return false;
			}
			$num=1;
		}
		$workerids=pdo_getcolumn('jy_yxw_worker',array('uniacid'=>$_SESSION['uniacid'],'id'=>$_SESSION['workerid']),'workerids');
		$workerids=json_decode($workerids,true);
		foreach($workerids as $wv){
			$njuese=pdo_getcolumn('jy_yxw_worker',array('uniacid'=>$_SESSION['uniacid'],'id'=>$wv['id']),'juese');
			if($njuese==$juese){
				$num++;
				if($num>1){
					return true;
				}
			}
		}
		return false;
	}
}
?>